package com.xiaowu.netmusic.controller;

import com.xiaowu.netmusic.service.CommentLikeService;
import com.xiaowu.netmusic.utils.Result;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/comment/like")
@AllArgsConstructor
@Tag(name = "评论点赞管理", description = "提供用户对评论点赞的相关操作接口")
public class CommentLikeController {

    private final CommentLikeService commentLikeService;

    @Operation(summary = "点赞评论", description = "用户对指定评论进行点赞")
    @PostMapping("/like")
    public Result<?> like(@RequestParam Long userId, @RequestParam Long commentId) {
        return commentLikeService.likeComment(userId, commentId)
                ? Result.success()
                : Result.error("点赞失败");
    }

    @Operation(summary = "取消点赞", description = "用户取消对指定评论的点赞")
    @PostMapping("/cancel")
    public Result<?> cancel(@RequestParam Long userId, @RequestParam Long commentId) {
        return commentLikeService.cancelLikeComment(userId, commentId)
                ? Result.success()
                : Result.error("取消点赞失败");
    }

    @Operation(summary = "判断是否点赞", description = "判断用户是否已点赞某评论")
    @GetMapping("/isLiked")
    public Result<?> isLiked(@RequestParam Long userId, @RequestParam Long commentId) {
        boolean liked = commentLikeService.isCommentLiked(userId, commentId);
        return Result.success(liked);
    }
}
